﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// Simple Service Administration Tool for WinNT based systems.
// Copyright © 2010 - Silvan Gehrig
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
// 
// Author:
//  Silvan Gehrig
//
// ---------------------------------------------------------------------
#endregion

#region Usings

using System.IO;
using System.Threading;
using log4net.Config;

#endregion

namespace SSATool.Common.Logging
{
    /// <summary>
    /// Provides static methods which are used to initialize the logging
    /// framework.
    /// </summary>
    public static class LoggerConfig
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Initializes the Logging framework using the given xml
        /// configuration file.
        /// </summary>
        /// <param name="xmlConfigFile">Relative or absolute path to the configuration xml file.</param>
        public static void RegisterConfigFile(string xmlConfigFile)
        {
            if (string.IsNullOrEmpty(Thread.CurrentThread.Name))
            {
                Thread.CurrentThread.Name = "StartThread"; // mark current thread as start up thread
            }

            using (FileStream fileToRead = File.Open(xmlConfigFile, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                XmlConfigurator.Configure(fileToRead);
            }
        }

        #endregion
    }
}
